var t = o(require("../../libs/mini/create")), e = o(require("../../store/index")), a = o(require("../../components/common/poster/poster")), n = o(require("./poster"));

function o(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function i(t, e, a) {
    return e in t ? Object.defineProperty(t, e, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = a, t;
}

function r(t) {
    return function() {
        var e = t.apply(this, arguments);
        return new Promise(function(t, a) {
            return function n(o, i) {
                try {
                    var r = e[o](i), s = r.value;
                } catch (o) {
                    o = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(o);
                    return void a(o);
                }
                if (!r.done) return Promise.resolve(s).then(function(t) {
                    n("next", t);
                }, function(t) {
                    n("throw", t);
                });
                t(s);
            }("next");
        });
    };
}

var s = getApp(), u = s.globalData.moduleHost;

t.default.Page(e.default, {
    use: [ "customLoading", "custom", "userInfo", "tempData" ],
    data: {
        loading: !0,
        type: "invite",
        miniCode: "",
        moduleHost: u,
        currentColor: "",
        showPickerColor: !1,
        form: {},
        posterSrc: "",
        showPopup: !1
    },
    onLoad: function(t) {
        var a = this, n = (t = t.type, e.default.getTempData(!0));
        this.setData({
            type: t,
            miniCode: n
        }), e.default.getCustom(function(t) {
            return t.title && wx.setNavigationBarTitle({
                title: t.title
            }), n ? void a.refreshPoster() : s.utils.modalText("获取信息失败，未知的邀请码。").then(function() {
                s.utils.alwaysBack();
            });
        });
    },
    showLoading: function() {
        var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", e = !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1];
        this.setData({
            loading: !0
        }), wx.showLoading({
            title: t,
            mask: e
        });
    },
    hideLoading: function() {
        this.setData({
            loading: !1
        }), wx.hideLoading();
    },
    onPosterSuccess: function(t) {
        t = t.detail, this.setData({
            posterSrc: t,
            loading: !1
        });
    },
    onPosterFail: function(t) {
        console.error("fail: ", t);
    },
    refreshPoster: function() {
        var t = (e = this.data).currentColor, e = e.form;
        return this.setData({
            posterSrc: "",
            loading: !0
        }), this.generatePoster(e, t);
    },
    generatePoster: function(t) {
        var e = this, o = t.line_1, i = t.line_2, s = t.line_3, u = t.line_4, l = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "";
        return r(regeneratorRuntime.mark(function t() {
            var r, c;
            return regeneratorRuntime.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return r = e.data.miniCode, c = l || e.data.$.custom.color || "#1890ff", c = (0, 
                    n.default)(r, c, o, i, s, u), t.next = 5, a.default.create(!0, c);

                  case 5:
                    e.setData({
                        loading: !1
                    });

                  case 6:
                  case "end":
                    return t.stop();
                }
            }, t, e);
        }))();
    },
    handleSavePoster: function() {
        var t, e = this;
        this.data.loading || (this.setData({
            loading: !0
        }), t = this.data.posterSrc, wx.saveImageToPhotosAlbum({
            filePath: t,
            success: function() {
                s.utils.modalText("已保存至相册，记得前往相册查看哦 ~").then(function() {
                    e.setData({
                        loading: !1
                    });
                });
            },
            fail: function(t) {
                s.utils.toastText("图片保存失败"), e.setData({
                    loading: !1
                });
            }
        }));
    },
    handleSaveMini: function() {
        var t, e = this;
        this.data.loading || (this.setData({
            loading: !0
        }), t = this.data.miniCode, wx.getImageInfo({
            src: t,
            success: function(t) {
                t = t.path, wx.saveImageToPhotosAlbum({
                    filePath: t,
                    success: function() {
                        s.utils.modalText("已保存至相册，记得前往相册查看哦 ~").then(function() {
                            e.setData({
                                loading: !1
                            });
                        });
                    },
                    fail: function(t) {
                        console.error("saveImageToPhotosAlbum ERROR: ", t), e.setData({
                            loading: !1
                        }), s.utils.toastText("图片保存失败");
                    }
                });
            },
            fail: function(t) {
                e.setData({
                    loading: !1
                }), console.error("getImageInfo ERROR: ", t), s.utils.toastText("获取图片失败");
            }
        }));
    },
    onPopupClose: function() {
        this.setData({
            showPopup: !1
        });
    },
    handleTextChange: function() {
        this.setData({
            showPopup: !0
        });
    },
    onInputChange: function(t) {
        var e = t.currentTarget.dataset.name;
        t = t.detail.value;
        this.setData(i({}, "form." + e, t));
    },
    onClearClick: function(t) {
        t = t.currentTarget.dataset.name, this.setData(i({}, "form." + t, ""));
    },
    handlePopupConfirm: function() {
        var t = this;
        this.data.loading || (this.setData({
            posterSrc: "",
            showPopup: !1,
            loading: !0
        }), this.refreshPoster().then(function() {
            t.hideLoading();
        }));
    }
});